package com.erification.web.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.erification.web.model.User;
import com.erification.web.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
public class RegisterAction extends ActionSupport{
	@Resource
	private UserService userService;
	private String message;
	private String Cmessage;
	private String captcha;
	private User user;

	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getCmessage() {
		return Cmessage;
	}
	public void setCmessage(String cmessage) {
		Cmessage = cmessage;
	}
	public String getCaptcha() {
		return captcha;
	}
	public void setCaptcha(String captcha) {
		this.captcha = captcha;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		String kapt = (String) ActionContext.getContext().getSession().get(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
		if(this.captcha.equals(kapt)) {
				message = userService.saveUser(user);
				if(message.equals("注册成功")){
					ActionContext.getContext().getSession().put("username", user.getUsername());
					return SUCCESS;
				} else return ERROR;
		} else {
			Cmessage = "验证码错误";
			return ERROR;
		}
	}
	
}
